﻿<local:MainPage
    x:Class="TheVerge.Phone.Pages.ForumEntriesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:con="clr-namespace:TheVerge.Phone.Controls"
    xmlns:local="clr-namespace:TheVerge.Phone.Pages"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    shell:SystemTray.IsVisible="True">
    <local:BasePage.Resources>
        <DataTemplate x:Key="itemTemplate">
            <Border BorderBrush="{StaticResource PhoneSubtleBrush}" BorderThickness="0,0,0,1" Padding="2">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" MaxHeight="70" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="{Binding Label, Converter={StaticResource capConv}}" Foreground="{StaticResource PhoneAccentBrush}" Grid.ColumnSpan="2" />

                    <Polygon Grid.Column="2" Grid.RowSpan="2" Fill="{StaticResource PhoneContrastBackgroundBrush}" Margin="0,28,6,0">
                        <Polygon.Points>
                            <Point X="14" Y="0" />
                            <Point X="10" Y="10" />
                            <Point X="26" Y="0" />
                        </Polygon.Points>
                    </Polygon>

                    <Border Background="{StaticResource PhoneContrastBackgroundBrush}" x:Name="tb"
                            HorizontalAlignment="Right"
                            Grid.Column="1" Grid.ColumnSpan="2" Margin="2">
                        <TextBlock Text="{Binding NumberOfComments, StringFormat=' {0} '}" Foreground="{StaticResource PhoneContrastForegroundBrush}" />
                    </Border>

                    <TextBlock Text="{Binding Title}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="{StaticResource PhoneHorizontalMargin}"
                               Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap" />

                    <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="2" VerticalAlignment="Top" Margin="{StaticResource PhoneHorizontalMargin}">
                        <StackPanel.Resources>
                            <Style TargetType="TextBlock" BasedOn="{StaticResource PhoneTextSubtleStyle}">
                                <Setter Property="Margin" Value="0" />
                                <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeSmall}" />
                            </Style>
                        </StackPanel.Resources>
                        <TextBlock Text="{Binding AuthorName}" />
                        <TextBlock Text=" | " />
                        <TextBlock Text="{Binding PublishedOn, Converter={StaticResource fnconv}}" />
                    </StackPanel>

                    <Button Click="Article_Click" Background="Transparent" Style="{StaticResource clearButtonStyle}"
                            HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0"
                            Grid.RowSpan="3" Grid.ColumnSpan="3" />
                </Grid>
            </Border>
        </DataTemplate>

        <Style TargetType="con:InfiniteScroller">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <ContentControl ContentTemplate="{StaticResource articleItemWithImageTemplate}" Content="{Binding}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"  />
                            <Button Click="Article_Click" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="Button" BasedOn="{StaticResource clearButtonStyle}" />
        
    </local:BasePage.Resources>
    <Grid x:Name="forumEntriesRoot" Background="{StaticResource PhoneBackgroundBrush}" Margin="-1" DataContext="{Binding Active}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Grid.RowSpan="2" Visibility="{Binding Converter={StaticResource nullVisConv}}">
            <Rectangle Fill="{StaticResource PhoneBackgroundBrush}" />
            <TextBlock Text="Loading . . . " HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource PhoneTextTitle1Style}" />
        </Grid>
        
        <Viewbox Height="120">
            <ContentControl ContentTemplate="{StaticResource fourmLogoTemplate}" Content="{Binding}" />
        </Viewbox>

        <controls:Pivot x:Name="thePiv" SelectionChanged="thePiv_SelectionChanged" Grid.Row="1"
                        HeaderTemplate="{StaticResource headerTemplate}"
                        ItemsSource="{Binding Entries}"
                        SelectedItem="{Binding SelectedEntries, Mode=TwoWay}"
                        TitleTemplate="{StaticResource PivotTitleTemplate}">
            <controls:Pivot.ItemTemplate>
                <DataTemplate>
                    <con:InfiniteScroller />
                </DataTemplate>
            </controls:Pivot.ItemTemplate>
        </controls:Pivot>

        <con:ArticleEntryControl x:Name="aec1" Grid.RowSpan="2" />
    </Grid>
    
</local:MainPage>